package com.lonely.fx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**
 * @date: 2022-07-07 15:24
 * @author: ztkj-hzb
 * @description:
 **/
public class ContentMenuSettingMain extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    /**
     *
     */
    @Override
    public void start(Stage primaryStage) throws Exception {

        HBox hBox = new HBox();
        hBox.setStyle("-fx-background-color: pink");

        //TODO 设置右键菜单，绑定 Control类的子类上
        ContextMenu contextMenu = new ContextMenu();
        MenuItem menuItem1 = new MenuItem("新建");
        MenuItem menuItem2 = new MenuItem("移除");
        contextMenu.getItems().addAll(menuItem1, menuItem2);

        TextField textField = new TextField("hello world");
        textField.setContextMenu(contextMenu);

        hBox.getChildren().add(textField);

        primaryStage.setScene(new Scene(hBox));
        primaryStage.setWidth(600);
        primaryStage.setHeight(500);
        primaryStage.show();


    }
}
